// 权限控制
import router from './router'
import store from './store'
const whiteList = ['/404', '/login']
router.beforeEach((to, from, next) => {
  if (store.state.user.token) {
    if (to.path === '/login') {
      next('/')
    } else {
      next()
      // 调用store下的user下的fetchUserInfo方法
      if (!store.state.user.userInfo.userId) {
        store.dispatch('user/getUserInfo')
      }
    }
  } else {
    if (whiteList.includes(to.path)) {
      next()
    } else {
      next('/login')
    }
  }
})
